package com.excel.util;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.util.PoiCellUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.property.ExcelWriteHeadProperty;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.excel.enums.LanguageTypeEnum;
import com.excel.strategy.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: 123
 */
@Slf4j
public class ExcelUtil {


    /**
     * 连接号-
     */
    public static final String HYPHEN_SPLIT = "-";

    /**
     * 格式
     */
    public static final String UTF8 = "utf-8";

    /**
     * 导出格式描述
     */
    public static final String CONTENT_DISPOSITION = "Content-Disposition";

    /**
     * 导出文件格式
     */
    public static final String ATTACHMENT_FILENAME = "attachment;filename=";

    /**
     * 导出excel上下文格式
     */
    public static final String CONTENT_JSON = "application/json";

    /**
     * 导出excel上下文格式
     */
    public static final String EXPORT_CONTEXT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    /**
     * excel文件后缀
     */
    public static final String FILE_XLSX_SUFFIX = ".xlsx";

    /**
     * 导出文件名时间格式化
     */
    public static final String FORMATTER_EXPORT_TIME_YMDHMS = "yyyyMMddHHmmss";

    public static final String DEFAULT_EMPTY_CONTENT = "-";

    public static final String EMPTY_STRING_CONTENT = " ";

    private ExcelUtil() {}


    public static void export(OutputStream outputStream, List<String> fields, Class<?> cla, List<?> data,
                              String sheetName) {
        export(outputStream, fields, cla, data, sheetName, null);
    }

    public static void exportSheets(OutputStream outputStream,
                                    Map<String, Class<?>> sheetClaMap,
                                    Map<String, List<?>> sheetDataMap,
                                    Map<String, List<String>> sheetIncludeFieldMap) {
        exportSheets(outputStream, sheetClaMap, sheetDataMap, sheetIncludeFieldMap, null);
    }

    /**
     * 导出数据到输出流
     *
     * @param outputStream 输出流
     * @param fields       字段信息
     * @param cla          对象
     * @param data         数据
     * @param sheetName    名称
     */
    public static void export(OutputStream outputStream, List<String> fields, Class<?> cla, List<?> data,
                              String sheetName, WriteHandler writeHandler) {
        if (Objects.isNull(writeHandler)) {
            //默认
            writeHandler = new CustomColumnWidthStyleStrategy();
        }
//        ExcelWriterSheetBuilder excelWriterSheetBuilder =
//                EasyExcelFactory.write(outputStream, cla)
//                        .registerWriteHandler(writeHandler)
//                        .registerWriteHandler(new CellWriteDateStrategy())
//                        .registerWriteHandler(new CustomRowWriteHandler())
//                        .registerWriteHandler(getStyleStrategy()).registerConverter(new ListConverter())
//                        .sheet(sheetName);
//        if (CollUtil.isNotEmpty(fields)) {
//            excelWriterSheetBuilder.includeColumnFieldNames(fields);
//        }
//        excelWriterSheetBuilder.doWrite(data);
    }

    public static void exportSheets(OutputStream outputStream,
                                    Map<String, Class<?>> sheetClaMap,
                                    Map<String, List<?>> sheetDataMap,
                                    Map<String, List<String>> sheetIncludeFieldMap,
                                    WriteHandler writeHandler) {
        if (Objects.isNull(writeHandler)) {
            //默认
            writeHandler = new CustomColumnWidthStyleStrategy();
        }

        for (String sheetName : sheetDataMap.keySet()) {
            Class<?> aClass = sheetClaMap.get(sheetName);
            ExcelWriterSheetBuilder excelWriterSheetBuilder = EasyExcelFactory.write(outputStream, aClass)
                            .registerWriteHandler(writeHandler)
                            .registerWriteHandler(new CellWriteDateStrategy())
                            .registerWriteHandler(new CustomRowWriteHandler())
                            .registerWriteHandler(getStyleStrategy())
                            .sheet(sheetName);
            List<?> data = sheetDataMap.get(sheetName);
            List<String> fields = sheetIncludeFieldMap.get(sheetName);
            if (CollUtil.isNotEmpty(fields)) {
                excelWriterSheetBuilder.includeColumnFieldNames(fields);
            }
            excelWriterSheetBuilder.doWrite(data);
        }
    }

//    public static void exportResponse(HttpServletResponse response, String fileName,
//                                      ExportSheetParam exportSheetParam,
//                                      LanguageTypeEnum typeEnum) {
//
//        try {
//            response.setContentType(EXPORT_CONTEXT);
//            response.setCharacterEncoding(UTF8);
//            String excelFileName = encodeFileName(fileName);
//            response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + excelFileName + FILE_XLSX_SUFFIX
//            );
//            exportSheetsWithParam(response.getOutputStream(), exportSheetParam, typeEnum);
//        } catch (Exception e) {
//            response.reset();
//            response.setContentType(CONTENT_JSON);
//            response.setCharacterEncoding(UTF8);
//            throw new RuntimeException("CustomErrorCodes.COMMON_EXPORT_ERROR");
//        }
//    }


//    public static void exportMultipleSheets(HttpServletResponse response,
//                                            String fileName,
//                                            List<MultipleSheetsParam> sheetsList,
//                                            WriteHandler writeHandler) {
//        try {
//            response.setContentType(EXPORT_CONTEXT);
//            response.setCharacterEncoding(UTF8);
//            String excelFileName = encodeFileName(fileName);
//            response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + excelFileName + FILE_XLSX_SUFFIX);
//
//            ExcelWriter excelWriter = EasyExcel
//                    .write(response.getOutputStream())
//                    .registerWriteHandler(new CustomColumnWidthStyleStrategy())
//                    .registerWriteHandler(getStyleStrategy())
//                    .build();

//            for (int i = 0; i < sheetsList.size(); i++) {
//                MultipleSheetsParam param = sheetsList.get(i);
//                String sheetName = param.getSheetName();
//
//                WriteSheet writeSheet = EasyExcel.writerSheet(i, sheetName)
//                        .registerWriteHandler(writeHandler)
//                        .registerWriteHandler(new CustomColumnWidthStyleStrategy())
//                        .head(param.getClazz()).build();
//                excelWriter.write(param.getData(), writeSheet);
//            }
//            excelWriter.finish();
//
//        } catch (Exception e) {
//            log.error("op=exportMultipleSheets | desc=导出异常", e);
//            response.reset();
//            response.setContentType(CONTENT_JSON);
//            response.setCharacterEncoding(UTF8);
//            throw new RuntimeException("CustomErrorCodes.COMMON_EXPORT_ERROR");
//        }
//    }

//    public static void exportSheetsWithParam(OutputStream outputStream,
//                                             ExportSheetParam exportSheetParam,
//                                             LanguageTypeEnum typeEnum) {
//        if (Objects.isNull(typeEnum)) {
//            typeEnum = LanguageTypeEnum.ZH_CN;
//        }
//        List<ExportSourceEnum> exportSourceEnumList = exportSheetParam.getExportSourceEnumList();
//
//        ExcelWriter excelWriter = EasyExcel
//                .write(outputStream)
//                .registerWriteHandler(new CellWriteDateStrategy())
//                .registerWriteHandler(new CustomColumnWidthStyleStrategy())
//                .registerWriteHandler(getStyleStrategy())
//                .build();
//
//        for (int i = 0; i < exportSourceEnumList.size(); i++) {
//            ExportSourceEnum exportSourceEnum = exportSourceEnumList.get(i);
//            String sheetName = NeptuneUtil.getLanguageContent(typeEnum, exportSourceEnum.getSheetName());
//
//            if (exportSourceEnum.getDynamicHead()) {
//                WriteSheet writeSheet = EasyExcel.writerSheet(i, sheetName)
//                        .head(exportSheetParam.getSheetDynamicHead(sheetName))
//                        .build();
//                excelWriter.write(exportSheetParam.getSheetDynamicData(sheetName), writeSheet);
//            } else {
//                WriteSheet writeSheet = EasyExcel.writerSheet(i, sheetName)
//                        .registerWriteHandler(new CustomColumnWidthStyleStrategy())
//                        .head(exportSheetParam.getSheetCla(sheetName)).build();
//                excelWriter.write(exportSheetParam.getSheetData(sheetName), writeSheet);
//            }
//        }
//        excelWriter.finish();
//    }

    private static HorizontalCellStyleStrategy getStyleStrategy() {
        // 表头样式
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        headWriteCellStyle.setWrapped(true);
        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        headWriteCellStyle.setLocked(true);
        headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headWriteCellStyle.setBorderTop(BorderStyle.THIN);
        headWriteCellStyle.setBorderBottom(BorderStyle.THIN);
        headWriteCellStyle.setBorderLeft(BorderStyle.THIN);
        headWriteCellStyle.setBorderRight(BorderStyle.THIN);
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontName("宋体");
        headWriteFont.setFontHeightInPoints(Short.valueOf((short) 11));
        headWriteFont.setBold(true);
        headWriteCellStyle.setWriteFont(headWriteFont);
        // 内容样式
        WriteCellStyle contentStyle = new WriteCellStyle();
        contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        WriteFont contentWriteFont = new WriteFont();
        contentWriteFont.setFontName("宋体");
        contentWriteFont.setFontHeightInPoints(Short.valueOf((short) 11));
        contentWriteFont.setBold(false);
        contentStyle.setWriteFont(contentWriteFont);

        return new HorizontalCellStyleStrategy(headWriteCellStyle, contentStyle);
    }

    public static void exportDynamic(HttpServletResponse response,
                                     List<List<String>> head,
                                     List<Map<Integer, String>> dataList,
                                     String sheetName,
                                     String fileName) {
        // 设置响应头
        response.setContentType(EXPORT_CONTEXT);
        response.setCharacterEncoding(UTF8);
        String excelFileName = encodeFileName(fileName);
        response.setHeader(
                CONTENT_DISPOSITION,
                ATTACHMENT_FILENAME + excelFileName + FILE_XLSX_SUFFIX
        );
        // 写入Excel
        ExcelWriterBuilder writerBuilder = null;
        try {
            writerBuilder = EasyExcel.write(response.getOutputStream())
                    .registerWriteHandler(new CustomerCellStyleStrategy());
        } catch (IOException e) {
            log.error("动态表头导出异常:{}", e);
//            throw new BizException(CustomErrorCodes.SYSTEM_ERROR);
        }
//        writerBuilder.sheet(sheetName).head(head).registerWriteHandler(new AutoWidthHandler()).doWrite(dataList);
    }


    /**
     * 自定义写入处理器
     */
    private static class CustomRowWriteHandler implements RowWriteHandler {

        @Override
        public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
                                    Integer rowIndex, Integer relativeRowIndex, Boolean isHead) {
            if (Boolean.TRUE.equals(isHead)) {
                Collection<String> includeColumnFieldNames = writeSheetHolder.getIncludeColumnFieldNames();
                if (CollectionUtils.isEmpty(includeColumnFieldNames)) {
                    return;
                }
                // 获取传入的包含的列(字段的名字list),将headMap的索引按照传入的列的顺序重新放入,即可实现排序
                ExcelWriteHeadProperty excelWriteHeadProperty = writeSheetHolder.getExcelWriteHeadProperty();
                Map<Integer, Head> headMap = excelWriteHeadProperty.getHeadMap();
                // 将headMap中的字段名字对应Head
                Map<String, Head> fieldNameHead = headMap.values().stream()
                        .collect(Collectors.toMap(Head::getFieldName, head -> head, (o1, o2) -> o1));
                int index = 0;
                for (String includeColumnFieldName : includeColumnFieldNames) {
                    // 按照includeColumnFieldNames中的顺序取出head重新覆盖
                    Head head = fieldNameHead.get(includeColumnFieldName);
                    if (head == null) {
                        continue;
                    }
                    headMap.put(index++, head);
                }
            }
        }
    }


    public static void exportResponse(HttpServletResponse response, List<String> fields, Class<?> cla, List<?> data,
                                      String sheetName, String fileName) {
        exportResponse(response, fields, cla, data, sheetName, fileName, null);
    }

    public static void exportResponse(HttpServletResponse response,
                                      Map<String, Class<?>> sheetClaMap,
                                      Map<String, List<?>> sheetDataMap,
                                      Map<String, List<String>> sheetIncludeFieldMap,
                                      String fileName) {
        exportResponse(response, sheetClaMap, sheetDataMap, sheetIncludeFieldMap, fileName, null);
    }

    /**
     * 导出数据到输出流
     *
     * @param response
     */
    private static void exportResponse(HttpServletResponse response,
                                       Map<String, Class<?>> sheetClaMap,
                                       Map<String, List<?>> sheetDataMap,
                                       Map<String, List<String>> sheetIncludeFieldMap,
                                       String fileName, WriteHandler writeHandler) {
        try {
            response.setContentType(EXPORT_CONTEXT);
            response.setCharacterEncoding(UTF8);
            String excelFileName = encodeFileName(fileName);
            response.setHeader(
                    CONTENT_DISPOSITION,
                    ATTACHMENT_FILENAME + excelFileName + FILE_XLSX_SUFFIX
            );
            exportSheets(response.getOutputStream(), sheetClaMap, sheetDataMap, sheetIncludeFieldMap, writeHandler);
        } catch (Exception e) {
            log.error("op=exportResponse | desc=导出异常", e);
            response.reset();
            response.setContentType(CONTENT_JSON);
            response.setCharacterEncoding(UTF8);
//            throw new BizException(CustomErrorCodes.COMMON_EXPORT_ERROR);
        }
    }

    public static void exportResponseWithWrapper(HttpServletResponse response, List<String> fields, Class<?> cla, List<?> data,
                                                 String sheetName, String fileName) {

        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        // 设置内容自动换行
        contentWriteCellStyle.setWrapped(true);


        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
                new HorizontalCellStyleStrategy(null, contentWriteCellStyle);

        exportResponse(response, fields, cla, data, sheetName, fileName, horizontalCellStyleStrategy);
    }

//    public static void exportResponseWithWrapperMultipleSheets(HttpServletResponse response,
//                                                               String fileName,
//                                                               List<MultipleSheetsParam> sheetsList) {
//
//        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//        // 设置内容自动换行
//        contentWriteCellStyle.setWrapped(true);
//
//
//        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
//                new HorizontalCellStyleStrategy(null, contentWriteCellStyle);
//
//        exportResponseMultipleSheets(response, sheetsList, fileName, horizontalCellStyleStrategy);
//    }


    /**
     * 导出数据到输出流
     *
     * @param response
     * @param fields
     * @param cla
     * @param data
     * @param sheetName
     */
    private static void exportResponse(HttpServletResponse response, List<String> fields, Class<?> cla, List<?> data,
                                       String sheetName, String fileName, WriteHandler writeHandler) {
        try {
            response.setContentType(EXPORT_CONTEXT);
            response.setCharacterEncoding(UTF8);
            String excelFileName = encodeFileName(fileName);
            response.setHeader(
                    CONTENT_DISPOSITION,
                    ATTACHMENT_FILENAME + excelFileName + FILE_XLSX_SUFFIX
            );
            export(response.getOutputStream(), fields, cla, data, sheetName, writeHandler);
        } catch (Exception e) {
            log.error("op=exportResponse | desc=导出异常", e);
            response.reset();
            response.setContentType(CONTENT_JSON);
            response.setCharacterEncoding(UTF8);
//            throw new BizException(CustomErrorCodes.COMMON_EXPORT_ERROR);
        }
    }

//    private static void exportResponseMultipleSheets(HttpServletResponse response, List<MultipleSheetsParam> sheetsList, String fileName,
//                                                     WriteHandler writeHandler) {
//        try {
//            response.setContentType(EXPORT_CONTEXT);
//            response.setCharacterEncoding(UTF8);
//            String excelFileName = encodeFileName(fileName);
//            response.setHeader(
//                    CONTENT_DISPOSITION,
//                    ATTACHMENT_FILENAME + excelFileName + FILE_XLSX_SUFFIX
//            );
//
//
//            //exportMultipleSheets(response, fileName, sheetsList, writeHandler);
//        } catch (Exception e) {
//            log.error("op=exportResponseMultipleSheets | desc=导出异常", e);
//            response.reset();
//            response.setContentType(CONTENT_JSON);
//            response.setCharacterEncoding(UTF8);
//            //throw new BizException(CustomErrorCodes.COMMON_EXPORT_ERROR);
//        }
//    }


    /**
     * 项目配置导入 不需要回填错误信息， 直接回显到前端， 前端展示
     */
    public static <T> List<T> projectConfigImportExcel(InputStream inputStream, Integer titleRows, Integer headerRows,
                                                       boolean needVerify, Class<T> pojoClass) throws IOException {
        if (inputStream == null) {
            return Collections.emptyList();
        }
        ImportParams params = new ImportParams();
        params.setTitleRows(titleRows);
        params.setHeadRows(headerRows);
        params.setSaveUrl("/excel/");
        params.setNeedSave(false);
        params.setNeedVerify(needVerify);
        try {
            return ExcelImportUtil.importExcel(inputStream, pojoClass, params);
        } catch (NoSuchElementException e) {
            throw new IOException("excel导入文件不能为空");
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }

    /**
     * excel 导入
     *
     * @param inputStream 文件输入流
     * @param titleRows   标题行
     * @param headerRows  表头行
     * @param needVerify  是否检验excel内容
     * @param pojoClass   pojo类型
     * @param <T>
     * @return
     */
    public static <T> List<T> importExcel(InputStream inputStream, Integer titleRows, Integer headerRows,
                                          boolean needVerify, Class<T> pojoClass) throws IOException {
        validateInputStream(inputStream);
        ImportParams params = new ImportParams();
        params.setTitleRows(titleRows);
        params.setHeadRows(headerRows);
        params.setSaveUrl("/excel/");
        params.setNeedSave(false);
        params.setNeedVerify(needVerify);
        params.setVerifyHandler(new ClassExcelVerifyHandler());
        try {
            return ExcelImportUtil.importExcel(inputStream, pojoClass, params);
        } catch (NoSuchElementException e) {
            throw new IOException("excel文件不能为空");
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }

    private static void validateInputStream(InputStream inputStream) throws IOException {
        if (inputStream == null) {
            throw new IOException("输入流不能为空");
        }
    }

    public static List<List<String>> readHead(InputStream inputStream, Integer sheetAt, Integer titleRows,
                                              Integer headerRows) {
        List<List<String>> headRowList = new ArrayList<>();
        try (Workbook workbook = WorkbookFactory.create(inputStream)) {
            Sheet sheet = workbook.getSheetAt(sheetAt);
            for (int row = titleRows; row < titleRows + headerRows; row++) {
                List<String> headRow = new ArrayList<>();
                Row headerRow = sheet.getRow(row);
                if (headerRow == null) {
                    continue;
                }
                Iterator<Cell> headerCellIterator = headerRow.iterator();
                while (headerCellIterator.hasNext()) {
                    Cell cell = headerCellIterator.next();
                    headRow.add(PoiCellUtil.getCellValue(cell));
                }
                headRowList.add(headRow);
            }
        } catch (Exception e) {
            log.error("op=readHead | desc=读取表头异常", e);
            throw new RuntimeException("CustomErrorCodes.COMMON_IMPORT_HEADER_ERROR");
        }
        return headRowList;
    }

    public static String encodeFileName(String name) {
        String currTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern(FORMATTER_EXPORT_TIME_YMDHMS));
        String fileName = name + HYPHEN_SPLIT + currTime;
        try {
            return URLEncoder.encode(fileName, UTF8).replaceAll("\\+", "%20");
        } catch (UnsupportedEncodingException e) {
            log.error("op=replaceFileNameSpecialChars | desc=替换文件名特殊字符异常", e);
        }
        return fileName;
    }

//    private static void export(HttpServletResponse response,
//                               List<ExportData> exportDataList,
//                               AbstractVerticalCellStyleStrategy strategy) {
//        try {
//            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
//            for (int i = 0; i < exportDataList.size(); i++) {
//                WriteSheet writeSheet = EasyExcel.writerSheet(i, exportDataList.get(i).getExportSourceEnum().getSheetName())
//                        .head(exportDataList.get(i).getExportClass())
//                        .registerWriteHandler(strategy)
//                        .build();
//                excelWriter.write(exportDataList.get(i).getExportDetailList(), writeSheet);
//            }
//            excelWriter.finish();
//        } catch (Exception e) {
//            log.error("op-exportSheetsWithSubjectParam-error:{}", e);
//        }
//    }

    private static void buildExportResponse(HttpServletResponse response, String fileName) {
        response.setContentType(EXPORT_CONTEXT);
        response.setCharacterEncoding(UTF8);
        String excelFileName = encodeFileName(fileName);
        response.setHeader(
                CONTENT_DISPOSITION,
                ATTACHMENT_FILENAME + excelFileName + FILE_XLSX_SUFFIX
        );
    }

//    public static void exportSheetsWithSubjectParam(HttpServletResponse response,
//                                                    List<ExportData> exportDataList,
//                                                    String fileName) {
//        buildExportResponse(response, fileName);
//        export(response, exportDataList, new CustomerCellStyleStrategy());
//    }

//    public static void exportSheetsWithReportResultParam(HttpServletResponse response,
//                                                         List<ExportData> exportDataList,
//                                                         String fileName,
//                                                         ExcelStyleContext context) {
//        ExcelWriter excelWriter = null;
//        try {
//            buildExportResponse(response, fileName);
//            EvalReportResultWriteStyleStrategy cellStyleStrategy = new EvalReportResultWriteStyleStrategy(
//                    new WriteCellStyle(),
//                    new WriteCellStyle(),
//                    context
//            );
//            EvalReportResultColumnWidthHandler widthHandler = new EvalReportResultColumnWidthHandler();
//            excelWriter = EasyExcel.write(response.getOutputStream()).build();
//            int index = 0;
//            for (ExportData exportData : exportDataList) {
//                List<List<String>> dynamicHeader = exportData.getDynamicHeader();
//                List<List<String>> dynamicData = exportData.getDynamicData();
//                WriteSheet sheet = EasyExcel.writerSheet(index, exportData.getExportSourceEnum().getSheetName())
//                        .head(dynamicHeader)
//                        .registerWriteHandler(cellStyleStrategy)
//                        .registerWriteHandler(widthHandler)
//                        .build();
//                excelWriter.write(dynamicData, sheet);
//                index++;
//            }
//            excelWriter.finish();
//        } catch (Exception e) {
//            log.error("op-exportSheetsWithReportResultParam-:{}", e);
//        }
//    }


}
